/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cassandrawindow;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class HandleDataTableCampIp {
    
    public static final String KEYSPACE                               =   "AdsData";
    public static final String ColumFamly                           =   "BannerViewCountCf";
    public static final String ColumFamlyBannerClickCountCf         =   "BannerClickCountCf";
    public static final String ColumFamlyBannerViewCountCf          =   "BannerViewCountCf";
    public static final String ColumFamlyCampaignClickCountCf       =   "CampaignCountCf";
    public static final String ColumFamlyCampaignViewCountCf        =   "CampaignViewCountCf";
    public static final String ColumFamlyCampaignIPCountCf          =   "CampaignIpCountCf";
    
    public void handleData() throws ParseException, InterruptedException, IOException
    {
        long first_time = System.currentTimeMillis();
        CassandraAction cassAct = new CassandraAction(ACCOUNT.CLUSTERNAME ,ACCOUNT.URL, ACCOUNT.PORT);
        cassAct.initReadWirte(KEYSPACE);
        MysqlDataManager67 mysqldatamanager = new MysqlDataManager67();
        //CqlDataManager cqldatamanager = new CqlDataManager();
        String currentDate = HandleDataTableDomainDate.handleDate();//2012-07-24
        //String currentDate = "2013-02-21";
        String sbff = cassAct.getIpByCampaign(currentDate, ColumFamlyCampaignIPCountCf);
        if(sbff.toString().length() > 1)
        {                       
            HandleImportData hid = new HandleImportData();
            String pathFile="";
            
            try {
                pathFile = hid.outToCsvcamIp(sbff);
                Debug.println("pathFile:"+pathFile);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            
            try {
                //get sys_date_cpc
                String strDate =  mysqldatamanager.getSysDateCPC();
                //Drop partition
                //mysql67.dropPartition(CONSTANT.V3_BAN_DATE_CS, strDate);
                MysqlDataManager67 mysql672 = new MysqlDataManager67(false);
                mysql672.beforeLoadData();
                mysql672.dropPartition(CONSTANT.V3_CAM_IP_CS, strDate);
                mysql672.loadToV3CamIpFromFile(pathFile);
                mysql672.shutdownConnection();                
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }        
        mysqldatamanager.shutdownConnection();        
        Debug.println("success campaignIp");
    }
}
